package com.fingard.dsp.bank.reqrespobj.diagnostics;

import com.fingard.constant.Format;
import com.fingard.dsp.bank.reqrespobj.ReqRespHeader;
import com.fingard.dsp.bank.reqrespobj.RetAtsBase;
import com.fingard.dsp.bank.reqrespobj.diagnostics.detail.RetAtsFrontStatusDetail;
import com.fingard.dsp.bankset.EnBfStatus;
import com.fingard.xml.XmlTextWriter;

//获取前置机信息
public class RetAtsBankFrontStatus extends RetAtsBase {

	public RetAtsBankFrontStatus(ReqRespHeader p_header){
		retHeader = p_header;
		retXmlWriter = new XmlTextWriter();//用于输出返回ATS的XML报文
	}
	
	public void writeTop(){
		retXmlWriter.writeStartDocument();
		retXmlWriter.writeStartElement("ATSYH");
		retXmlWriter.writeStartElement("TransResp");
		
		retXmlWriter.writeElementString("TransType", retHeader.transType);
		retXmlWriter.writeElementString("TransSeqID", retHeader.transSeqID);
		
		retXmlWriter.writeStartElement("TransParam");
	}
	
	public void writeTail(){
		retXmlWriter.writeEndDocument();
	}
	
	/*
    <DetailRecord>
      <URID>前置机URID</URID>
      <Code>前置机代码</Code>
      <Name>前置机名称</Name>
      <Entity>订户</Entity>
      <SystemCode>账户分组</SystemCode>
      <Server>服务地址，如10.111.2.22:4040</Server>
      <Status>最新状态，normal-正常，exception-异常</Status>
      <StatusInfo>最新状态信息</StatusInfo>
      <StatusTime>最新状态时间，格式yyyy-MM-dd HH:mm:ss</StatusTime>
    </DetailRecord>
* */
	public void writeRetDetail(RetAtsFrontStatusDetail p_detail){
		
		retXmlWriter.writeStartElement("DetailRecord");
		retXmlWriter.writeElementString("URID", p_detail.urid);
		retXmlWriter.writeElementString("Code", p_detail.code);
		retXmlWriter.writeElementString("Name", p_detail.name);
		retXmlWriter.writeElementString("Entity", p_detail.entity);
		retXmlWriter.writeElementString("SystemCode", p_detail.systemCode);
		retXmlWriter.writeElementString("Server", p_detail.server);
		retXmlWriter.writeElementString("ServerType", "直联服务");
		if(p_detail.status == EnBfStatus.normal){
			retXmlWriter.writeElementString("Status", "normal");
		}
		else if(p_detail.status == EnBfStatus.exception){
			retXmlWriter.writeElementString("Status", "exception");
		}
		else{
			retXmlWriter.writeElementString("Status", "init");
		}
		retXmlWriter.writeElementString("StatusInfo", p_detail.statusInfo);
		if(p_detail.StatusTime != null){
			retXmlWriter.writeElementString("StatusTime", Format.DateTimeFormat.format(p_detail.StatusTime));
		}
		else{
			retXmlWriter.writeElementString("StatusTime", "");
		}
		retXmlWriter.writeEndElement();

	}
}
